<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* php-ats admin 
* @author Mav Peri
*/

class query extends CI_Controller {
		public function index()
	{
		echo "nothing here";
	}
	
	/**
	* returns a key value pair for a given ATS metric
	* @param key is the ATS variable, see /htdocs/models/trafficserver.php for supported variables
	* replace / with _slash_ in the key  when requesting
	*/
	function getvalue($key){		
		$key = str_replace("_slash_", "/", $key);
		$key = str_replace("%20", " ", $key);
		$key = str_replace("&#40;", "(", $key);
		$key = str_replace("&#41;", ")", $key);			
		$settings = parse_ini_file('/etc/php-ats.ini', true);
		$feed = json_decode(file_get_contents($settings['http']['read_endpoint']), true);		
		echo "".$key.""."\t".$feed[$key]['value'];
	}
	
	/**
	* returns an html widget of some key metrics
	*/
	function widget(){
		$settings = parse_ini_file('/etc/php-ats.ini', true);
		$data['enabled'] = array('Open origin server connections', 'Open client connections', 'Cache percent free', 'Document hit rate', 'Transactions per second', 'Client throughput (Mbits/sec)', 'Client transactions in progress');
		$data['percentages'] = array('Cache percent free', 'Document hit rate');
		$data['numbers'] = array('Transactions per second', 'Client throughput (Mbits/sec)');
		$data['feed'] = json_decode(file_get_contents($settings['http']['read_endpoint']), true);
		$this->load->view('widget', $data);
	}
	
}

?>